package soccerscope.view;

import java.awt.event.ActionEvent;
import java.util.Vector;

import javax.swing.JComboBox;

import soccerscope.model.ScenePlayModeList;
import soccerscope.model.ScenePlayModeListItem;
import soccerscope.model.ScenePlayModeListObserver;
import soccerscope.model.SceneSet;
import soccerscope.model.WorldModel;

public class ChronologicScenePlayModeJumper
    extends AbstractSceneJumper
    implements ScenePlayModeListObserver {

  private static final long serialVersionUID = 1952046359577513197L;

  private JComboBox         box;

  /**
   * Creates a new SceneJumper to jump from a scene in a play mode to another
   * scene of another play mode.
   * 
   * @param scenePlayer
   *          the scene player to set the new scene.
   */
  public ChronologicScenePlayModeJumper(
      ScenePlayer scenePlayer) {

    super(scenePlayer);
    SceneSet sceneSet = WorldModel.getSceneSet();
    ScenePlayModeList pml = sceneSet.getScenePlayModeList();

    this.box = new JComboBox(new Vector(pml.getAllScenePlayModes()));
    this.add(this.box);
    pml.addObserver(this);
  }

  /**
   * This method is called, when a the play mode has changed
   * 
   * @param item
   *          the scene number and the new play mode in one object
   */
  public void newScenePlayModeAdded(ScenePlayModeListItem item) {

    this.box.addItem(item);
  }

  /**
   * Thie method is called, when the whole list has changed, e.g. after loading
   * 
   */
  public void allChanged() {

    SceneSet sceneSet = WorldModel.getSceneSet();
    ScenePlayModeList pml = sceneSet.getScenePlayModeList();

    this.remove(this.box);
    this.box = new JComboBox(new Vector(pml.getAllScenePlayModes()));
    this.add(this.box);
    this.box.setVisible(true);
  }

  /**
   * Jumps to the selected scene.
   */
  public void actionPerformed(ActionEvent arg0) {

    this.jumpToScene(((ScenePlayModeListItem) this.box.getSelectedItem())
        .getScene());
  }

}
